package com.ms.service.impl;

import com.ms.mapper.UserMapper;
import com.ms.pojo.Employee;
import com.ms.pojo.Employee_login;
import com.ms.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
@Service
public class UserServiceImpl implements UserService{
        @Autowired
        private UserMapper userMapper;

        @Override
        public Employee_login login(String emp_username, String emp_password) {
            // 检查参数是否为空
            if (emp_username == null || emp_username.isEmpty() || emp_password == null || emp_password.isEmpty()) {
                return null;
            }
            // 查询用户信息
            Employee_login employeelogin = userMapper.selectByUsernameAndPassword(emp_username, emp_password);
            // 检查用户是否存在
            if (employeelogin == null) {
                return null;
            }return employeelogin;


}
    /**
     * 员工注册
     *
     * @param employeeLogin 登录信息
     * @return 是否成功
     */
    @Override
    public boolean register(Employee_login employeeLogin) {
        try {
            // 先设置登录信息的默认值
            employeeLogin.setCreateTime(new Date());
            employeeLogin.setStatus(1); // 1表示正常
        }
        catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return userMapper.insert(employeeLogin) > 0;


    }
}

